package action.backend;

import java.util.List;
import model.Item;
import model.Sector;
import model.User;

import org.apache.struts2.convention.annotation.ParentPackage;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import dao.ItemDAO;

@ParentPackage(value = "showcase")
public class ItemAction extends ActionSupport implements ModelDriven<Item> {

	private static final long serialVersionUID = 1L;
	private ItemDAO item_dao = new ItemDAO();

	private String oper= new String();
	private String id;
	private String nombre;
	private Sector sector;

	public String execute() {

		Item item;

		if (oper.equalsIgnoreCase("add")) {

			item = new Item();
			item.setNombre(nombre);
			item.setSector(sector);
			item_dao.saveItem(item);
		} else if (oper.equalsIgnoreCase("edit")) {

			item = item_dao.findById(Integer.parseInt(id));
			item.setNombre(nombre);
			item.setSector(sector);
			item_dao.saveItem(item);
			
		} else if (oper.equalsIgnoreCase("del")) {
			item = item_dao.findById(Integer.parseInt(id));
			item_dao.delete(item);
		}
		return SUCCESS;
	}

	public String getJSON() {
		return execute();
	}

	@Override
	public Item getModel() {
		// TODO Auto-generated method stub
		return new Item();
	}

	// Getters and Setters for Attributes
}
